//
//  GroupNoticeTableViewCell.m
//  AAIM
//
//  Created by 远的小布丁 on 2019/12/17.
//  Copyright © 2019 AAIM. All rights reserved.
//

#import "GroupNoticeTableViewCell.h"

@implementation GroupNoticeTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
-(void)setModel:(BTMessageModel *)model{
    _model=model;
    //    SystemMessageApplyCreateGroup = 1,               // 申请开群
    //    SystemMessageAuditCreateGroup = 2,          // 审核通过申请开群
    //    SystemMessageDeleteGroup = 3,             // 解散群
    //    SystemMessageApplyJoinGroup = 4,                 // 申请加群
    //    SystemMessageAuditJoinGroup = 5,            // 通过申请加群
    //    SystemMessageRefusedJoinGroup = 6,            // 拒绝申请加群
    //    SystemMessageDeleteGroupMember = 11,               // 群移除某成员
    //    SystemMessageMemberExit = 13                // 群成员退出
    
    ContactModel * invitedUserModel = [[UserDataBaseTool shareUserDataBaseTool] queryFriends:model.fuuid];
    
    self.titleLbl.text=model.nickname;
    self.contentLbl.text=model.msg;
    [self.headerImg sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",userHeaderImage, model.head]] placeholderImage:kHeadPlaceholderImage];
    
    if (model.type_id  ==  SystemMessageApplyJoinGroup) {
        self.titleLbl.text=invitedUserModel.nickname;
        self.rejectBtn .hidden  = self.acceptBtn.hidden =NO;
        [self.headerImg sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",userHeaderImage, invitedUserModel.head]] placeholderImage:kHeadPlaceholderImage];
        self.statusLbl.hidden = YES;
        if (model.addfriendState == 1 ) {
            self.rejectBtn .hidden  = self.acceptBtn.hidden =YES;
                   self.statusLbl.text = @"已同意";
            self.statusLbl.hidden = NO;
               }else if (model.addfriendState == 2){
                   self.rejectBtn .hidden  = self.acceptBtn.hidden =YES;
                   self.statusLbl.text = @"已拒绝";
                   self.statusLbl.hidden = NO;
               }
        
       
    }else{
        [self.headerImg sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",userHeaderImage, model.head]] placeholderImage:kHeadPlaceholderImage];
        self.rejectBtn .hidden  = self.acceptBtn.hidden =YES;

        
    }
}
-(void)setShowUI{
    [self.contentView addSubview:self.headerImg];
    [self.contentView addSubview:self.rejectBtn];
    [self.contentView addSubview:self.acceptBtn];
    [self.contentView addSubview:self.titleLbl];
    [self.contentView addSubview:self.noticeLbl];
    [self.contentView addSubview:self.contentLbl];
    [self.contentView addSubview:self.statusLbl];
    
    [_headerImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView.mas_left).offset(15.f);
        make.top.mas_equalTo(self.contentView.mas_top).offset(15.f);
        make.size.mas_equalTo(CGSizeMake(38.f, 38.f));
    }];
    [_rejectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.contentView.mas_right).offset(-15.f);
        make.centerY.mas_equalTo(self.headerImg.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(SCALAE_WIDTH(44.f), 22.f));
    }];
    [_acceptBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.rejectBtn.mas_left).offset(-8.f);
        make.centerY.mas_equalTo(self.headerImg.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(SCALAE_WIDTH(44.f), 22.f));
    }];
    [_titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.headerImg.mas_right).offset(8.f);
        make.top.mas_equalTo(self.contentView.mas_top).offset(15.f);
        make.right.mas_equalTo(self.acceptBtn.mas_left).offset(-10.f);
    }];
    [_noticeLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.headerImg.mas_right).offset(8.f);
        make.top.mas_equalTo(self.titleLbl.mas_bottom);
        make.right.mas_equalTo(self.acceptBtn.mas_left).offset(-10.f);
    }];
    [_contentLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.headerImg.mas_right).offset(8.f);
        make.top.mas_equalTo(self.noticeLbl.mas_bottom).offset(3);
        make.right.mas_equalTo(self.rejectBtn.mas_left).offset(-10.f);
        make.bottom.mas_equalTo(self.contentView.mas_bottom).offset(-15.f);
    }];
    [_statusLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.right.mas_equalTo(self.contentView.mas_right).offset(-15.f);
        make.width.offset(SCALAE_WIDTH(46.f));
    }];
}

-(UIImageView *)headerImg{
    if (!_headerImg) {
        _headerImg = [[ UIImageView alloc]init];
        _headerImg.layer.cornerRadius = 19.f;
        _headerImg.layer.masksToBounds = YES;
        _headerImg.backgroundColor = [UIColor redColor];
    }
    return _headerImg;
}

-(UILabel *)titleLbl{
    if (!_titleLbl) {
        _titleLbl = [[UILabel alloc]init];
        _titleLbl.textColor = KHEXCOLOR(@"#262B2F");
        _titleLbl.font = kMainFont(15.f);
        _titleLbl.text = @"群聊/用户";
    }
    return _titleLbl;
}
-(UILabel *)noticeLbl{
    if (!_noticeLbl) {
        _noticeLbl = [[UILabel alloc]init];
        _noticeLbl.textColor = KHEXCOLOR(@"#AFAFAF");
        _noticeLbl.font = kMainFont(11.f);
        _noticeLbl.hidden = YES;
        //        _noticeLbl.text = @"申请加入群聊xxx";
    }
    return _noticeLbl;
}

-(UILabel *)contentLbl{
    if (!_contentLbl) {
        _contentLbl = [[UILabel alloc]init];
        _contentLbl.textColor = KHEXCOLOR(@"#AFAFAF");
        _contentLbl.font = kMainFont(11.f);
        _contentLbl.numberOfLines = 0;
        _contentLbl.text = @"你好，我是xxx,很高兴认识你！";
    }
    return _contentLbl;
}

-(UIButton *)rejectBtn{
    if (!_rejectBtn) {
        _rejectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_rejectBtn setTitle:@"拒绝" forState:UIControlStateNormal];
        [_rejectBtn setBackgroundColor:KHEXCOLOR(@"#62A5F3")];
        _rejectBtn.titleLabel.font = kMainFont(12.f);
        [_rejectBtn setTitleColor:KHEXCOLOR(@"ffffff") forState:UIControlStateNormal];
        _rejectBtn.layer.cornerRadius = 5;
        _rejectBtn.layer.masksToBounds = YES;
        _rejectBtn.tag=100;
        [_rejectBtn addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _rejectBtn;
}

-(UIButton *)acceptBtn{
    if (!_acceptBtn) {
        _acceptBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_acceptBtn setTitle:@"接受" forState:UIControlStateNormal];
        [_acceptBtn setBackgroundColor:KHEXCOLOR(@"#62A5F3")];
        _acceptBtn.titleLabel.font = kMainFont(12.f);
        [_acceptBtn setTitleColor:KHEXCOLOR(@"ffffff") forState:UIControlStateNormal];
        _acceptBtn.layer.cornerRadius = 5;
        _acceptBtn.layer.masksToBounds = YES;
        _acceptBtn.tag=200;
        [_acceptBtn addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _acceptBtn;
}
-(void)clickButton:(UIButton*)sender
{
    if ([self.delegate respondsToSelector:@selector(didGroupNoticeTableCell:selecedButton:)]) {
        [self.delegate didGroupNoticeTableCell:self selecedButton:sender];
    }
}
- (UILabel *)statusLbl{
    if (!_statusLbl) {
        _statusLbl = [[UILabel alloc]init];
        _statusLbl.textColor = KHEXCOLOR(@"#AFAFAF");
        _statusLbl.font = kMainFont(12.f);
        _statusLbl.text = @"已通过";
        _statusLbl.hidden = YES;
    }
    return _statusLbl;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
